﻿EntityTrigger = Eg.Entity.extend({
  size: {
    x: 16,
    y: 16
  },
  _wmScalable: true,
  _wmDrawBox: true,
  _wmBoxColor: 'rgba(196, 255, 0, 0.7)',
  target: null,
  delay: -1,
  delayTimer: null,
  canFire: true,
  type: Eg.Entity.TYPE.NONE,
  checkAgainst: Eg.Entity.TYPE.A,
  collides: Eg.Entity.COLLIDES.NEVER,
  init: function (x, y, settings) {
    if (settings.checks) {
      this.checkAgainst = Eg.Entity.TYPE[settings.checks.toUpperCase()] || Eg.Entity.TYPE.A;
      delete settings.check;
    }
    this.parent(x, y, settings);
    this.delayTimer = new Eg.Timer();
  },
  check: function (other) {
    if (this.canFire && this.delayTimer.delta() >= 0) {
      if (typeof (this.target) == 'object') {
        for (var t in this.target) {
          var ent = Eg.game.getEntityByName(this.target[t]);
          if (ent && typeof (ent.triggeredBy) == 'function') {
            ent.triggeredBy(other, this);
          }
        }
      }
      if (this.delay == -1) {
        this.canFire = false;
      } else {
        this.delayTimer.set(this.delay);
      }
    }
  },
  update: function () { }
});